clc;clear;
x = 0.99:0.0002:1.01;
%g = (((((((x - 8).*x + 28).*x - 56).*x + 70).*x - 56).*x + 28).*x - 8).*x + 1;
%h = (x - 1).^8;
%plot(x,f)
%plot(x,g)
%plot(x,h)
% 初始化基数、精度、指数范围 
beta = 2; p = 3;
uflf=2^-1;
oflf=2*(2-2^(1-p));
% 所有可能的指数和尾数 
n_list = [1 1.25 1.5 1.75]; 
add=n_list*beta^-1
n_list=[n_list add]
add=n_list*beta
n_list=[n_list add]
subn_list = [0.25 0.5 0.75 1 1.25 1.5 1.75]; 
add=subn_list*beta^-1
subn_list=[subn_list add]
add=subn_list*beta
subn_list=[subn_list add]
subn_list = unique(subn_list);
% 绘制所有的浮点数在实轴上的位置 
figure; 
plot([min(n_list)-1, max(n_list)+1], [0 0], 'k'); 
hold on;
scatter(n_list, zeros(size(n_list)), 'filled');
xlim([min(n_list)-1, max(n_list)+1]);
% 加入标签
xlabel('Value');
ylabel('Frequency'); 
title('Floating point numbers in the system');
figure; 
plot([min(subn_list)-1, max(subn_list)+1], [0 0], 'k'); 
hold on;
scatter(subn_list, zeros(size(subn_list)), 'filled');
xlim([min(subn_list)-1, max(subn_list)+1]);
% 加入标签
xlabel('Value');
ylabel('Frequency'); 
title('addsubFloating point numbers in the system');
